<?php
namespace Admin\Model;
use Think\Model;
class CodeModel extends Model {
	public $page; //当前页
	public $perpage; //每页显示
	public $id; //ID
	public $post; //提交的信息 数组
	public $table='zjy_code';
	public $ids; //IDs 数组，用于删除

	//添加代号提交
	public function add_post()
	{
		$Model=M("Code");
		if($Model->add($this->post)){
			return true;
		}else{
			return false;
		}
	}
	//获取代号列表
	public function get_list()
	{
		$page=intval($this->page);
		$perpage=intval($this->perpage);
		$Model=M("Code");
		$start=($page-1)*$perpage;
		$list=$Model->query("select * from ".$this->table." order by `id` desc limit $start,$perpage");
		return $list;
	}
	//获得信息总数
	public function get_info_total()
	{
		$Model=M("Code");
		$count=$Model->count();
		return $count;
	}
	//获取分类信息
	public function get_info()
	{
		$id=intval($this->id);
		$Model=M("Code");
		$info=$Model->where('id='.$id)->find(); //!!修改到这里
		return $info;
	}
	//提交编辑的分类
	public function edit_post()
	{
		$Model=M("Code"); // 实例化对象
		$condition['id'] = $this->post['id'];
		$data=$this->post;
		$result=$Model->where($condition)->save($data);
		if($result === false) {
			return false;
		}else{
			return true;
		}
	}
	//删除
	public function delete_ids()
	{
		$ids=$this->ids;
		$Model=M("Code");
		foreach($ids as $v){
			$condition['id']=$v;
			if(!$Model->where($condition)->delete()){
				return false;
			}
		}
		return true;
	}
}